package xiaohongshu

import (
	"marketing-server/global"
	"marketing-server/model/marketing/xiaohongshu"
	xiaohongshuReq "marketing-server/model/marketing/xiaohongshu/request"
)

type XhsTicketService struct{}

// CreateXhsTicket 创建xhsTicket表记录
// Author [yourname](https://github.com/yourname)
func (xhsTicketService *XhsTicketService) CreateXhsTicket(xhsTicket *xiaohongshu.XhsTicket) (err error) {
	err = global.MustGetGlobalDBByDBName("xiaohongshuAlias").Create(xhsTicket).Error
	return err
}

// DeleteXhsTicket 删除xhsTicket表记录
// Author [yourname](https://github.com/yourname)
func (xhsTicketService *XhsTicketService) DeleteXhsTicket(id string) (err error) {
	err = global.MustGetGlobalDBByDBName("xiaohongshuAlias").Delete(&xiaohongshu.XhsTicket{}, "id = ?", id).Error
	return err
}

// DeleteXhsTicketByIds 批量删除xhsTicket表记录
// Author [yourname](https://github.com/yourname)
func (xhsTicketService *XhsTicketService) DeleteXhsTicketByIds(ids []string) (err error) {
	err = global.MustGetGlobalDBByDBName("xiaohongshuAlias").Delete(&[]xiaohongshu.XhsTicket{}, "id in ?", ids).Error
	return err
}

// UpdateXhsTicket 更新xhsTicket表记录
// Author [yourname](https://github.com/yourname)
func (xhsTicketService *XhsTicketService) UpdateXhsTicket(xhsTicket xiaohongshu.XhsTicket) (err error) {
	err = global.MustGetGlobalDBByDBName("xiaohongshuAlias").Model(&xiaohongshu.XhsTicket{}).Where("id = ?", xhsTicket.Id).Updates(&xhsTicket).Error
	return err
}

// GetXhsTicket 根据id获取xhsTicket表记录
// Author [yourname](https://github.com/yourname)
func (xhsTicketService *XhsTicketService) GetXhsTicket(id string) (xhsTicket xiaohongshu.XhsTicket, err error) {
	err = global.MustGetGlobalDBByDBName("xiaohongshuAlias").Where("id = ?", id).First(&xhsTicket).Error
	return
}

// GetXhsTicketInfoList 分页获取xhsTicket表记录
// Author [yourname](https://github.com/yourname)
func (xhsTicketService *XhsTicketService) GetXhsTicketInfoList(info xiaohongshuReq.XhsTicketSearch) (list []xiaohongshu.XhsTicket, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
	// 创建db
	db := global.MustGetGlobalDBByDBName("xiaohongshuAlias").Model(&xiaohongshu.XhsTicket{})
	var xhsTickets []xiaohongshu.XhsTicket
	// 如果有条件搜索 下方会自动创建搜索语句
	err = db.Count(&total).Error
	if err != nil {
		return
	}

	if limit != 0 {
		db = db.Limit(limit).Offset(offset)
	}

	err = db.Find(&xhsTickets).Error
	return xhsTickets, total, err
}
func (xhsTicketService *XhsTicketService) GetXhsTicketPublic() {
	// 此方法为获取数据源定义的数据
	// 请自行实现
}
